
Uec3.AddOutPurchaseOrderButton = Ext.extend(AddPurchaseOrderButton, {
	loadBtnsUrl : RES_PATH + '/purchase/loadNotOnlineBtns.do',
	loadOrdersUrl : RES_PATH + '/purchase/loadNotOnlineOrders.do',
	purNotOnlineDeal : function() {
		this.purDeal();
	},
	/**
	 * 非在线保存
	 */
	purNotOnlineSave : function() {
		this.main_win.purchase_status_hidden.setValue('0');
		this.main_win.purchase_wkflId_hidden.setValue('1');
		this.purBatchInsert();
	},
	/**
	 * 非在线提交
	 */
	purNotOnlineSubmit : function() {
		this.main_win.purchase_status_hidden.setValue('2');
		this.main_win.purchase_wkflId_hidden.setValue('1');
		this.purBatchInsert();
	},
	/**
	 * 非在线修改
	 */
	purNotOnlineUpdate : function() {
		this.main_win.purchase_status_hidden.setValue('0');
		this.purBatchUpdate();
	},
	/**
	 * 非在线修改并提交
	 */
	purNotOnlineUpdateToSubmit : function() {
		this.main_win.purchase_status_hidden.setValue('2');
		this.purBatchUpdate();
	},
	purNotOnlineRestore : function() {
		this.purRestore();
	},
	purNotOnlineDelete : function() {
		this.purDelete();
	},
	/**
	 * 非在线订单新建下一张
	 */
	purNotOnlineNextOne : function() {
		var desktop = Uec3.App.getDesktop();   
		desktop.launchWindowByParam("addOutPurchaseOrderWindowCreator",{});
	},
	purNotOnlineQuery : function() {
		this.purQuery();
	},
	purNotOnlineAgreeRecieve : function() {
		this.purAgreeRecieve();
	},
	purNotOnlineReset : function() {
		this.purReset();
	}
});

Uec3.AddOutPurchaseOrderWindow = Ext.extend(AddPurchaseOrderWindow, {
	buttonMudule : Uec3.AddOutPurchaseOrderButton,
	initCreateUrl : RES_PATH + '/purchase/notOnlineToCreate.do',
	loadDetailsUrl : RES_PATH + '/purchase/loadNotOnlineDetails.do',
	
	initShowUrl : RES_PATH + '/purchase/notOnlineToShow.do',
	partnerUrl : RES_PATH + "/partner/query_partner!queryPartner.do",
	partnerQualify : '0',
	createPurchaseItemGrid : function() {
		// 创建grid，装载明细数据
		return new Ext.grid.EditorGridPanel( {
//			style : {padding : '2px'},
//			height : 280,
			clicksToEdit : 1,
			flex : 1,
			colModel : this.purchase_item_colName,
			store : this.purchase_item_store,
			tbar : this.purchase_toolbar
//			,
//			selModel : new Ext.grid.RowSelectionModel(
//                 {
//                    moveEditorOnEnter : true,
//                    singleSelect : true
//                 }
//	        )
		});
	},
	initPanel : function(initParams) {
		this.createAllHidden();
		this.createAllCmb();
		
		this.priceEditor = new Ext.form.NumberField({
			regex : /([1-9][0-9]*(\.\d+)?)|(0\.\d+)/,
			regexText : '您只能够输入数字'
		});
		
		this.purchase_item_colName = this.createPurchaseItemColName();
		this.purchase_item_record = this.createPurchaseItemRecord();
		this.purchase_item_store = this.createPurchaseItemStore();
		
		this.partner_combox = this.createPartnerCombox();
		this.address_combox = this.createAddressCombox();
		
		this.purchase_toolbar = this.createToolBar();
		
		this.purchase_item_grid = this.createPurchaseItemGrid();
		this.purchase_panel = this.createPurchasePanel();

		this.purchase_item_colName.setHidden(3, true);
		
//		this.quotation_form_item = this.createQuotationFormItem();
//		this.quotation_item_store = this.createQuotationItemStore();
//		this.quotation_item_grid = this.createQuotationItemGrid();
//		this.quotation_panel = this.createQuotationPanel();
		
//		this.setPurGridHeight(300);
//		this.setPurPanelHeight(450);
//		this.setJoinPanelHeight(700);
		
//		this.join_panel = this.createJoinPanel();
		this.capturePurStoreEvent();
		
		this.add(this.purchase_panel);
		
		this.on('show', function() {
			
			this.loadContent(initParams);
		
		}, this, {single : true})
		
//		this.doLayout();
//		this.show();
//		this.creator.app.getDesktop().addAutoRun(this.getId());
		
	},
	createDelPurBtn : function(value, metadata, record, rowIndex, colIndex, store) {
		
			if(this.status && this.status != '-1' && this.status != '0') {
				return '已确认';
			}
			
//			if(Uec3.App.getDesktop().windows.getActive() == this) {
//				alert('yiyang');
//			}
			
			return '<a style="font-size:12px;" href=javascript:getRunningWindow(' + 
				this.creatorIndex + 
				',Uec3.AddOutPurchaseOrderWindowCreator).removeRecordFromStore("' + 
				record.id + '"); >删除</a>';
						
	},
	createJoinPanel : function() {
		return new Ext.Panel({
			frame : true,
			height : 600,
			autoScroll : true,
			items : [this.purchase_panel]
		});
	},
//	autoFillDetailForm : function() {
//    	 var source = this.source_cmb.getValue();
////    	 alert(this.pur_detailForm);
//	    	 var code = this.pur_detailForm.getForm().findField("code").getValue();
//	    	 if(code){
//	    	     Ext.Ajax.request({
//	    	        url :Uec3.App.Constants.homeUrl+"/part/queryPart!getPartByCodeAndSource.do",
//	                params :{queryParam:Ext.encode({code:code,source:source})},
//	                method :"post",
//	                callback :function(options,success,response){
//	                     
//	                },
//	                success:function(response,options) {	                	 
//	                	  var resp = Ext.decode(response.responseText);
//	                	  
//	                	  if(resp) {
////	                	     this.pur_detailForm.getForm().setValues(resp);
//	                	  	 this.pur_detailForm.getForm().findField("partId").setValue(resp.id);
//	                	  	 this.pur_detailForm.getForm().findField("name").setValue(resp.name);
//	                	     this.pur_detailForm.getForm().findField("measurementUnit").setValue(resp.measurementUnit);
//	                	     this.pur_detailForm.getForm().findField("brand").setValue(resp.brand);
//	                	     this.pur_detailForm.getForm().findField("origin").setValue(resp.origin);
//	                	     this.pur_detailForm.getForm().findField("carModel").setValue(resp.carModel);
//	                	     this.pur_detailForm.getForm().findField("level1Id").setValue(resp.level1Id);
//	                	     this.pur_detailForm.getForm().findField("level1Name").setValue(resp.level1Name);
//	                	     this.pur_detailForm.getForm().findField("level2Name").setValue(resp.level2Name);
//	                	     this.pur_detailForm.getForm().findField("orderQuantity").focus();
//	                	  } else {
//	                	     Ext.MessageBox.alert("提示","此零件编码和来源无相关零件信息,请重试");
//	                	     this.pur_detailForm.getForm().findField("source").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("partId").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("name").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("measurementUnit").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("brand").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("origin").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("carModel").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("level1Id").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("level1Name").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("level2Name").el.dom.value='';
//	                	     this.pur_detailForm.getForm().findField("orderQuantity").el.dom.value='';
//	                	  }					       
//	                }.createDelegate(this),
//	                failure:function(response,options){
//	                      Ext.MessageBox.alert("提示","数据加载异常");
//	                }.createDelegate(this)
//	    	   });	    		    	 
//	       }else{
//	         Ext.MessageBox.alert("提示","请填写零件编码");
//	       }		         
//    },
//    createDetailForm : function() {
//    	var ds_code_select = new Ext.data.JsonStore({
//			url : PurchaseUrl.PUR_FIND_PART_BY_CODE_URL,
//			root:'root',
//			totalProperty:'totalProperty',
//		    fields:[{name:'code',type:'string'}]
//		});
//		
//    	return new Ext.form.FormPanel({
//	        labelSeparator : "：",
//			frame:true,
//			border:false,
//			defaults:{width:246},
//			labelWidth:60,
//			manager:Uec3.App.getDesktop().windows,
//			items:[
//			    {  
//				    xtype:'combo',
//					allowBlank : false,
//					blankText : '零件编码不能为空',
//					name : 'code',					
//					fieldLabel:'零件编码',
//					valueField:'code',
//	                displayField : 'code',
//   	  				mode : 'remote',
//   	  				queryParam :'queryParam',
//   	  				queryDelay:500,
//   	  				minChars :2,
//   	  				store : ds_code_select,
//   	  				pageSize:10,
//	   				selectOnFocus : true,
//	   				triggerAction : 'all',
//	   				loadingText : '加载中...',	   				
//	   				emptyText : '请输入零件编码',
//	   				listeners :{
//					   'select':function(){
//					   	  var value = this.getValue();
//					      this.ownerCt.getForm().el.dom.reset();
//					      this.setValue(value);
//					   },
//					   'change' : function() {
//					   		this.ownerCt.getForm().el.dom.reset();
//					   		this.setValue(this.getValue());
//					   }
//					}
//			    }, {
//			        xtype:'combo',
//					//name : 'source',
//					fieldLabel:'零件来源',
//					valueField:'varIndex',
//	                displayField : 'varName',
//   	  				mode : 'remote',
//	   				hiddenName:'source',
//	   				value:'',
//	   				store : this.sourceType_store,
//	   				selectOnFocus : true,
//	   				forceSelection  :true,
//	   				editable:true,
//	   				triggerAction : 'all',
//	   				loadingText : '加载中...',	   				
//	   				emptyText : '请选择零件来源',	   				
//	   				listeners :{
//					   'select' : this.autoFillDetailForm.createDelegate(this)
//					}
//			    }, {
//			        xtype:'textfield',
////					allowBlank : false,
//					blankText : '零件名称不能为空',
//					name : 'name',
//					fieldLabel:'零件名称',
//					readOnly:true,
//					style:{background:'#dddddd'}
//			    }, {
//			    	xtype:'textfield',				    
////					allowBlank : false,
//					blankText : '零件单位不能为空',
//					name : 'measurementUnit',
//					fieldLabel:'单位',
//	   				readOnly:true,
//	   				style:{background:'#dddddd'}
//			    }, {
//			    	xtype:'hidden',
//			    	name : 'partId'
//			    }, {
//			    	xtype:'hidden',
//			    	name : 'level1Id'
//			    }, {
//			    	xtype:'hidden',
//			    	name : 'level1Name'
//			    }, {
//			    	xtype:'hidden',
//			    	name : 'level2Name'
//			    }, {
//			        xtype:'textfield',
////					allowBlank : false,
//					readOnly:true,
//					name : 'carModel',
//					fieldLabel:'车型',
//					style:{background:'#dddddd'}
//			    }, {
//			        xtype:'textfield',
////					allowBlank : false,
//					readOnly:true,
//					name : 'brand',
//					fieldLabel:'品牌',
//					style:{background:'#dddddd'}
//			    }, {
//			        xtype:'textfield',
////					allowBlank : false,
//					readOnly:true,
////					blankText : '产地不能为空',
//					name : 'origin',
//					fieldLabel:'产地',
//					style:{background:'#dddddd'}
//			    }, {
//			        xtype:'numberfield',
//					name : 'orderQuantity',
//					fieldLabel:'采购数量',					
//	                allowNegative: false	               	                
//			    }, {
//			        xtype:'numberfield',
////					allowBlank : false,
//					name : 'price',
//					fieldLabel:'采购价',
////					allowBlank: false,
//	                allowNegative: false	               
//			    }
//			],
//			buttons:[
//			     {
//			     	text:'提交',
//			        handler : this.submitForm.createDelegate(this)
//			     },{
//			     	text:'重置',
//			        handler : this.resetForm.createDelegate(this)
//			     },{
//			     	text:'关闭',
//			     	handler : function(){
//			     	    this.detail_wind.hide();
//			     	}.createDelegate(this)
//			     }
//			],
//			buttonAlign:'center'
//	    });
//    },
//    submitForm : function() {
//    	 //取得表单数据	  	 	  
//	       if(!this.pur_detailForm.getForm().isValid()){
//	          return;
//	       }
//	       
//	       if((this.pur_detailForm.getForm().findField("orderQuantity").getValue()+'').trim() == '') {
//	       		Ext.MessageBox.alert("提示", "采购数量不能为空.");
//	       		return;
//	       }
//	       
//	       this.pur_detailForm.enable();	    
//	       var fmValue = this.pur_detailForm.getForm().getValues();
//	       
////	       var code_index = this.purchase_item_store.findExact('code', newRecord.code);
////	       var source_index = this.purchase_item_store.findExact('source', newRecord.source);
////	       if(code_index != -1 && source_index != -1) {
////	       		Ext.Msg.alert('提示', '对不起,该行记录已经存在了..');
////	       		return;
////	       } 
//	       
//	       var validateExist = false;
//	       Ext.each(this.purchase_item_store.getRange(), function(rec) {
//	       		if(rec.data.code + '&' + rec.data.source + '' == fmValue.code + '&' + fmValue.source + '') {
//	       			validateExist = true;
//	       			return false;
//	       		}
//	       });
//	       
//	       if( !validateExist ) {
//	          //增加明细
//	       	  this.purchase_item_store.add(new this.purchase_item_record(fmValue));	       	  
//              this.purchase_item_grid.getSelectionModel().selectFirstRow();
//  	          this.pur_detailForm.form.el.dom.reset(); 
//  	          this.pur_detailForm.enable();
//  	          this.pur_detailForm.getForm().findField("code").focus();
//	       } else {
//	       		Ext.Msg.alert('提示', '对不起,该行记录已经存在了..');
//	       }
//	       
//    },
//    resetForm : function() {
//    		this.pur_detailForm.form.reset(); 
//	  	    this.pur_detailForm.enable();
//	  	    this.pur_detailForm.getForm().findField("code").focus();
//
////	  	    var columns = this.purchase_item_grid.getColumnModel().columns;
////	        Ext.each(columns, function(value,index,arr) {
////	             var cellName = value.dataIndex;
////	             var field = this.pur_detailForm.form.findField(cellName);
////				 if(!field.isDisable){
////				    field.el.dom.value = '';
////				 }		             
////	        });
//    },
    createToolBar : function() {
//    	//创建弹出窗口
//		this.detail_wind = new Ext.Window({
//			layout:'fit',
//		    width:380,
//		    closeAction:'hide',
//		    height:400,
//			resizable :true,
//			shadow : true,
//			modal :true,
//		    closable:true,
//		    bodyStyle:'padding:5 5 5 5',
//		    animCollapse:true,
//			items:[this.pur_detailForm]
//		});
//    	
//    	function addDetailData() {
//    		if(this.partner_combox.getValue() == null || (this.partner_combox.getValue()+'').trim() == '') {
//				Ext.Msg.alert(PurChaseAlert.PROMOTE_ERROR, '对不起,您还没有选择供货单位..');
//				return;
//			}
//    		
//			this.detail_wind.setTitle("新增订单明细");
//			this.detail_wind.get(0).getForm().reset();
//	        this.detail_wind.show();
//		}
		
		//创建工具栏组件
		return new Ext.Toolbar({
		  items:[
			{text : '[新增明细]', iconCls : 'icon-add', handler : this.addDetailData.createDelegate(this)},
			{text : '[删除全部]', iconCls : 'icon-del', handler : this.delAllRecords.createDelegate(this)}
		   ]
		});
	},
	addDetailData : function() {
		if(this.partner_combox.getValue() == null || (this.partner_combox.getValue()+'').trim() == '') {
			Ext.Msg.alert(PurChaseAlert.PROMOTE_ERROR, '对不起,您还没有选择供货单位..');
			return;
		}
		
		this.creator.app.getDesktop().launchWindowByParam('purchasePartPropSearchWindowCreator', 
			{'purGrid' : this.purchase_item_grid, 'purRecord' : this.purchase_item_record, 'partnerId' : this.partner_combox.getValue()});
	}
	
	
});

Uec3.AddOutPurchaseOrderWindowCreator = Ext.extend(AddPurchaseOrderWindowCreator, {
	id : 'addOutPurchaseOrderWindowCreator',
	init : function() {
		this.ordersName = '非在线采购订单';
		this.ordersNameEn = 'not_online_purchase_order';
	},
	getTypeWindow : function() {
		return Uec3.AddOutPurchaseOrderWindow;
	}
});

